package com.woniuxy.wd.dao.util;

import java.io.IOException;
import java.util.Properties;

public abstract class DAOFactory {

	private static DAOFactory factory;
	private static Object initLock = new Object();
	private static final String DEFAULT_FACTORY = "com.woniuxy.wd.dao.util.MSSQLFactory";

	@Deprecated
	protected DAOFactory() {
	}

	public static DAOFactory getFactory() {

		if (factory == null) {
			synchronized (initLock) {
				if (factory == null) {
					try {
						Properties pro = new Properties();
						pro.load(DAOFactory.class.getResourceAsStream("/config.properties"));
						String s = pro.getProperty("facotry");

						String className = "";
						if (s == null || s.trim().length() <= 0)
							className = DEFAULT_FACTORY;
						else
							className = s;

						factory = (DAOFactory) Class.forName(className)
								.newInstance();
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}

		return factory;
	}

	public abstract DAOInterface getInstance(String name);

}
